home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / batch / library / batutl2 / send.doc < prev    next >
Text File  |  1986-08-15  |  27KB  |  469 lines

  1.    ¢4 L                                   SEND.COM 1.6
  2.  
  3.  
  4.          INTRODUCTION
  5.  
  6.                SEND.COM is an enhanced version of the ECHO command, ideal
  7.          for sending escape sequences to the printer or screen.  The
  8.          documentation is primarily a tutorial on ECHO, SEND and redirection
  9.          of output.  If you already feel expert on ECHO and redirection, you
  10.          can skip to the final SUMMARY section to get a short manual on
  11.          SEND.
  12.                SEND, its source code, documentation, and demonstration files
  13.          are copyright 1985 by Howard Rumsey and Barry Simon.  They are
  14.          placed in public domain with one restriction and may be used for any
  15.          purpose including commercial use.  It is recomended that the the
  16.          full set of files be distributed together.  The sole restriction
  17.          is that the two files with copyright notices must be distributed
  18.          with these copyright notices.
  19.                Version 1.5 differs from the unnumbered version 1.0 by
  20.          including discussion of redirection of send through COMMAND.COM and
  21.          additional $<Cap Letters> commands.
  22.                SEND.COM was written by Howard Rumsey.  The source file is
  23.          found on the disk together with several demonstration files:
  24.                MONODEMO.BAT
  25.                COLORDEM.BAT
  26.                KEYRD.BAT
  27.                KEYOFF.BAT
  28.                PRINTDEM.BAT
  29.          The first four require you to have installed ANSI.SYS via your
  30.          CONFIG.SYS file.  The first two illustrate the use of SEND with
  31.          monochrome and color monitors respectively.  Keyrd will redefine
  32.          your F9 key to mean "dir" followed by <Enter> and F10 to mean "cls"
  33.          followed by <Enter>.  Keyoff returns the keys to their original
  34.          meaning.  The final batch file will illustrate the use of SEND if
  35.          you have an IBM graphics or compatible printer attached to LPT1.
  36.          This batch file can be run on either monitor, but if you have a
  37.          color monitor, you should run it with that as tne active monitor.
  38.          The demonstration files and this documentation were written by
  39.          Barry Simon.
  40.                The following files are also included:
  41.                BOLDPRN.BAT: Uses SEND to printout a file of your choice in
  42.                    boldprint on an IBM printer.  Type in the command
  43.                        "boldprn 'filename'"
  44.                TRIAL.TXT: Used in printdem to illustrate boldprn.bat
  45.                ANSISYS.ART: An article by B. Simon, which first appeared in
  46.                    the CAPITOL PC Monitor which describes the use of
  47.                    ANSI.SYS.
  48.          The batch files have numerous remarks embedded in them and you
  49.          should copy them to your printer.  You should note that you
  50.          couldn't do that if these batch files had used ECHO and embedded
  51.          escape characters rather than SEND!
  52.                These programs are hereby placed in the public domain.
  53.  
  54.                Comments on this program can be sent to:
  55.                   Barry Simon                      Howard Rumsey
  56.                   Caltech 253-37         or        Caltech 158-79
  57.                   Pasadena, CA 91125               Pasadena, CA 91125
  58.                                                    CompuServe 72426,3722
  59.                This documentation can be printed out by turning on your
  60.          printer, making sure that the paper is properly aligned and typing
  61.          "copy send.doc prn" at a DOS prompt.  If you have an IBM graphics
  62.          printer, you can get an even nicer copy by typing "boldprn send.doc"
  63.          at the DOS prompt.
  64.  
  65.  
  66.          INSTALLING SEND.COM
  67.                Some effort has been expended to keep SEND.COM under 512
  68.          bytes so it takes up only one sector if you have a floppy based
  69.          system.  In that case, you need to copy SEND.COM to your utility
  70.          disk.  SEND is not resident so the disk needs to be present
  71.          whenever SEND is invoked.  On a hard disk system copy SEND.COM to a
  72.          directory which is one of your DOS path search directories set by
  73.          the PATH command.
  74.  
  75.  
  76.          USING ECHO
  77.                You may be used to exploiting ECHO in your batch files but
  78.          may not be aware that it can be invoked from the DOS command line.
  79.          If that is the case, type in at the DOS prompt:
  80.                echo hello
  81.          You need to also hit <Enter> but I won't keep saying that.  The
  82.          response is amusing but not useful.  Next try:
  83.                echo hello > prn
  84.  
  85.                                       SEND  page 2
  86.  
  87.  
  88.          More interesting!  Still not so useful but at least if you ever
  89.          want to use your printer as a typewriter (why anyone would want to
  90.          do this in preference to using a real word processor is beyond me!)
  91.          you can do it yourself without needing a BASIC program which does
  92.          precisely that.
  93.                Now try
  94.                echo <Ctrl G>
  95.          where "<Ctrl G>" means to hit a "control-G", that is to depress the
  96.          <Ctrl> key and strike the G and try
  97.                echo <Ctrl G> > prn
  98.          These are decidedly more interesting and you may even think of some
  99.          uses for them in batch files!
  100.                Next try turning off your printer, carefully aligning your
  101.         printer paper, turning your printer back on and typing
  102.                echo <Ctrl L> > prn
  103.          <Ctrl L> is the command to send a "top of form" to your printer but
  104.          if you look carefully you will discover that more than a top of
  105.          form was sent to the printer.  ECHO automatically inserts a
  106.          carriage return-line feed pair (CR-LF) to the end of any line so
  107.          your last command first sent a top of form but then advanced the
  108.          paper one additional line.  Annoying, isn't it?
  109.                Next try:
  110.                echo <Esc>
  111.          and
  112.                echo <Ctrl [>
  113.          (Escape and Control-[ are the same).  This doesn't do what you
  114.          might hope.  <Esc> is interpreted by DOS as a desire on your part
  115.          to abort the present command and thus you cannot use ECHO at the
  116.          command line to send an <Esc> to either the screen or your printer.
  117.          This is unfortunate since ANSI.SYS allows you to do all
  118.          sorts of nice things if you send the proper "escape sequences" to
  119.          the screen and many printers can be told to turn on boldface or
  120.          other neat things by sending escape sequences to them.  You can
  121.          send such sequences to the printer by using some word processors
  122.          (even EDLIN (ugh!) if you use its <Ctrl V> feature) to make a file
  123.          with embedded escape characters which you can copy to your printer.
  124.          But you then need to have these files around and you have files
  125.          with embedded control characters which you may have trouble
  126.          printing out or sending over a modem.
  127.                SEND is intended to remedy these defects of ECHO:
  128.                1. It does not terminate line in a CR-LF combination; one can
  129.                  add such a pair "by hand".
  130.                2. Typing "send ^G" is equivalent (except for the lack of a
  131.                  CR-LF) to typing "echo <Ctrl G>" so one need not fill files
  132.                  with control characters.
  133.                3. Typing "send ^[E > prn" will send a <Esc>E to the printer
  134.                  thereby turning on "emphasized" print.
  135.          In addition, as will be explained, SEND supports the PROMPT $-
  136.          characters.
  137.  
  138.  
  139.          SEND: CONTROL CHARACTERS
  140.                SEND works much like ECHO but if the string to be echoed
  141.          includes the caret (<Shift 6> which appears as ^), different rules
  142.          apply.  SEND will replace ^a by the character <Ctrl A> (ASCII 1),
  143.          etc.  ^ followed by any letter is replaced by the corresponding
  144.          control character whether the letter is upper case or lower case.
  145.          The remaining control characters:
  146.                ^@=ASCII 0
  147.                ^[=ASCII 27 (1B Hex)=<Esc>
  148.                ^\=ASCII 28 (1C Hex)
  149.                ^]=ASCII 29 (1D Hex)
  150.                ^^=ASCII 30 (1E Hex)
  151.                ^_=ASCII 31 (1F Hex)
  152.          may be included by following a caret by the appropriate symbol.
  153.          Obviously, ^[, the escape character will be used most often.  If ^
  154.          is followed by any other ASCII code such as ^2 or ^? or ^*, a
  155.          control character is also sent but the exact rules needn't concern
  156.          us.
  157.                If you wish to "send" a caret the string "$^" will have the
  158.          dollar sign striped away and a caret will be sent.  Thus the
  159.          command "send ^^a" will send the two characters <Ctrl ^> (ASCII 30)
  160.          followed by a (ASCII 97) while the command "send $^^a" will send
  161.          the two characters caret (ASCII 94) followed by <Ctrl A> (ASCII 1).
  162.                SEND does not automatically terminate any line in a CR-LF
  163.          (ASCII 13,ASCII 10) pair.  Thus typing "echo hello" at the DOS
  164.          command line will result in two lines on the screen before the
  165.          next DOS prompt: one line saying hello and the other a blank line.
  166.  
  167.                                       SEND  page 3
  168.  
  169.  
  170.          Typing "send hello" will only produce the one line saying hello.
  171.          If one wants the CR-LF pair, one can insert it "by hand"; thus
  172.          "send hello^M^J" will have the exact same effect  as "echo hello".
  173.          As we will see in the next section "send hello$_" is also
  174.          equivalent.  It is important to remember to put in these CR-LF by
  175.          hand if you are using SEND in a batch file to echo a message to the
  176.          screen.  For example the four line batch file
  177.                echo off
  178.                cls
  179.                send hello
  180.                send there
  181.          will produce the string "hellothere" on one line on the screen
  182.          while adding $_ after "hello" or even replacing the last two lines
  183.          by
  184.                send hello$_there
  185.          will produce a two line message with one word on each line.
  186.  
  187.  
  188.          SEND: $ LOWER CASE CHARACTERS
  189.                SEND supports the $-meta string conventions of the DOS PROMPT
  190.          command with one important changes (see $h below).  Specifically,
  191.          if a $ appears in a string following a SEND command (EXCEPTION: if
  192.          the $ is immediately preceded by a caret ^$ is interpreted as <Ctrl
  193.          D> unless of course its preceded by two carets...), a special
  194.          interpretation is made if the $ is immediately followed by one of
  195.          the following:
  196.                $,^
  197.                g,l,b,q
  198.                h,_,e
  199.                t,d,p,v,n
  200.                P,M,D,Y,T as descibed in the next section
  201.          In all other cases, the $ is ignored so that "send $a" will send
  202.          only "a" to the screen.  "$$" and "$^" follow the same rule of
  203.          stripping away the $ except that the $ and ^ are sent in their
  204.          conventional meaning rather than as special symbols for SEND.
  205.                The case of the letter following $ is significant. $G will be
  206.          interpreted as G while $g as >.
  207.                $g,$l,$b,$q correspond to the characters >,<,|,=
  208.          respectively.   You can use the ordinary "=" in a line starting with
  209.          "send", but you CANNOT type >,< or | in such a line since DOS will
  210.          interpret these symbols as redirection or piping.  You must use
  211.          the $-meta string instead.  For example, if you use FANSI-CONSOLE
  212.          and want to send the ANSI code "<esc>[>4h" typing the command "send
  213.          ^[[>4h" will make a file "4h" with two bytes in it while "send
  214.          ^[[$g4h" will do exactly what you want.
  215.                $h is equivalent to ^H, ASCII 8, the "backspace" which, if
  216.          sent to the screen, moves the cursor back one space.  Unlike the
  217.          PROMPT $h, the SEND $h does not erase the previous character.  Thus
  218.          "send a$h" will show an "a" on the screen and "send a$hb" will show
  219.          a "b" on the screen since the cursor will backspace one unit and
  220.          the b will overwrite the a.  But the command "send a$hb>file" will
  221.          produce a file with three bytes: a,<Ctrl H>,b.
  222.                $_ is equivalent to ^M^J, i.e. to a CR-LF pair.
  223.                $e is equivalent to ^[, the escape character (ASCII 27).
  224.                $t and $d send the time and date in the form returned by the
  225.          TIME and DATE commands.  Thus the time will appear as HH:MM:SS:hh.
  226.          If you only want the hours and minutes to appear on the screen, you
  227.          can type "send $t$h$h$h$h$h$h      ". (There are six spaces after
  228.          the final $h and they are important!).
  229.                $p will send the current full pathname including the current
  230.          drive such as "C:\bin\batfiles" or "C:\".
  231.                $v returns the current DOS version and $n the current default
  232.          drive letter without a trailing colon.
  233.  
  234.          SEND: $ UPPER CASE CHARATERS
  235.                Send also supports a small number of extensions of the propmt
  236.          meta strings:
  237.                $P: For any directory but the root directory $P will send
  238.          $p\; for the root directory, $P sends just \.  Thus if a file has
  239.          name as its filespec, "send $Pname" will always return the full
  240.          path-and-filespec while "send $p\name" will only work correctly if
  241.          you're not in the root directory.
  242.                $T: returns the time in HHMM form so if its 9:15:37:45 AM, it
  243.          will return 0915 and if its the same time PM, it will return 2115.
  244.                $M: returns the month in MM form so January is 01 and
  245.          December is 12.
  246.                $D: returns the day in DD form so on the first, you'll get 01
  247.          and on the twentieth 20.
  248.                $Y: returns the last two digits of the current year.
  249.  
  250.  
  251.                                       SEND  page 4
  252.  
  253.  
  254.                These last four metastrings are especially useful in
  255.          connection with redirection through command.com as discussed below.
  256.  
  257.          SEND AND ANSI.SYS
  258.                One of the most useful things you can do with SEND is exploit
  259.          the ANSI.SYS device driver.  ANSI.SYS is a file that comes with DOS
  260.          (version 2.0 and higher).  You need to load it in your CONFIG.SYS
  261.          file.  If you already have such a file, add a line
  262.                device=ansi.sys
  263.          to it and place ANSI.SYS in your root directory or, even better,
  264.          place ANSI.SYS in a directory, say GEORGE and add a line
  265.                device=\george\ansi.sys
  266.          to your CONFIG.SYS file. If you don't have such a file, add one to
  267.          your root directory with one of the above lines and while you're at
  268.          it, you should probably add files=20 and buffers=15 (unless the
  269.          memory of your computer is very limited).
  270.               You can read about the syntax of the ANSI.SYS commands in the
  271.          DOS 2.0 manual or the DOS 3.0 technical reference.  ANSI.SYS can be
  272.          used to control screen colors on a color monitor, and attributes on
  273.          a monochrome monitor.  For example,
  274.                send $e[1;31;42m
  275.          will produce an unpleasant screen while
  276.                send $e[1;33;44m
  277.          will be more to your liking.  Actually, it is best to set your
  278.          screen colors using the DOS PROMPT command.  You can use SEND to
  279.          call up colors and attributes for effect in batch files.  The two
  280.          batch files MONODEMO and COLORDEM provided illustrate this.
  281.                You can also use SEND and ANSI.SYS to redefine keys in DOS.
  282.          This is illustrated by KEYRD.  Try the F9 and F10 keys after
  283.          running KEYRD and turn off these special meanings by running
  284.          KEYOFF.
  285.                An article which originally appeared in the CAPITOL PC
  286.          Monitor is included on the disk if you want to know more about how
  287.          to use ANSI.SYS.
  288.  
  289.          REDIRECTION OF OUTPUT
  290.                DOS, following UNIX, supports two virtual devices called
  291.          "standard input" (stdin) and "standard output" (stdout).  Programs
  292.          rather than sending their output to a specific device like the
  293.          screen or printer can send them to stdout and similarly rather than
  294.          take input from a specific device, they can take it from stdin.  If
  295.          not specified otherwise, stdout is sent to the currently active
  296.          screen and stdout is taken from the keyboard (i.e. the DOS command
  297.          line).  However, one can redirect stdout to another device.  For
  298.          this to work the program MUST send its output to stdout.  For
  299.          example, the "main output" of the COPY command goes not to stdout
  300.          but to the second file specified on the command line; only the
  301.          message that COPY sends goes to stdout.  Thus "copy send.doc prn"
  302.          will print this file on your printer, but "copy send.doc > prn" will
  303.          print the error message
  304.  
  305.                            File cannot be copied onto itself
  306.                                     0 File(s) copied
  307.  
  308.                If a program takes its input from stdin, that too can be
  309.          redirected.  One redirects output using the symbol ">" and input
  310.          using "<".
  311.                SEND sends its output to stdout and that can be redirected,
  312.          for example to a printer or file.  It takes its input from the
  313.          keyboard rather than from stdin so one cannot redirect input.
  314.  
  315.          SENDING PRINTER CONTROLS
  316.                SEND can also be used for sending control sequences to your
  317.          printer.  Unfortunately, the sequences to be used tend to be highly
  318.          dependent on the brand and/or model of your printer.  The PRINTDEM
  319.          batch file included and the examples presented here work for the
  320.          IBM graphics printer and compatibles.  You may need to figure out
  321.          how to modify things to handle your own printer.  The simplest
  322.          example is a one line batch file entitled tf.bat
  323.                send ^L> prn
  324.          Typing tf at the DOS command line will cause your printer to eject
  325.          a page.  You might even want to define a function key to mean tf.
  326.          A more sophisticated example is the five line batch file
  327.          BOLDPRN.BAT, provided as a sample file:
  328.                echo off
  329.                cls
  330.                send $eE$eG>prn
  331.                copy %1 prn
  332.                send $eF$eH>prn
  333.  
  334.                                       SEND  page 5
  335.  
  336.          Thus typing "boldprn MYFILE" will print a boldface (=emphasized and
  337.          doublestrike) copy of myfile on your printer.  You might consider
  338.          adding the line:
  339.                send $P%1 printed on $d>prn
  340.          before the "copy..." line.
  341.                Other examples can be found in the PRINTDEM batch file.
  342.                A particularly useful way of sending printer codes is to use
  343.          send in CED synonyms if you have the program CED.
  344.  
  345.  
  346.          ECHO, SEND AND PARAMETERS
  347.                If you have a batch file called foo.bat and type the command
  348.                      foo hello
  349.          at the DOS command line, hello is treated by DOS as the first
  350.          parameter, denoted %1.  Thus the line "echo %1 there" in the batch
  351.          file will type the phrase "hello there" on the screen.  Since this
  352.          is a DOS service, "send %1 there" will work the same way.  DOS
  353.          makes the replacement before the line in the batch file is
  354.          processed.
  355.  
  356.          USING BOTH ECHO AND SEND
  357.                There is no reason not to use both ECHO and SEND on different
  358.          lines of batch files.  In the demonstration files we only used SEND,
  359.          but if one doesn't need the special features of SEND, it is more
  360.          convenient to use ECHO and not have to worry about inserting the
  361.          CR-LF pairs by hand.
  362.  
  363.  
  364.          REDIRECTING SEND THROUGH COMMAND.COM
  365.                If you use SEND for a while, you will wish you could send its
  366.          output to the command line rather than just to the screen.  That is
  367.          typing "send ren myfile file$M$D" on December 15, will echo "ren
  368.          myfile fill1215" on the screen but will not issue that command to
  369.          DOS.  One can use DOS's pipe facility to issue such commands to DOS
  370.          but some care is needed.  If not done exactly right, your system
  371.          will hang although the only effect will be the need to reboot.
  372.                One can make a new "shell" of DOS by issuing the command
  373.          "command" if the DOS file COMMAND.COM is in the current directory
  374.          or in your DOS search path.  This new shell remains resident until
  375.          the command "exit" is issued.
  376.                To explain the care needed consider some examples.  Unless
  377.          you like rebooting, don't actually try these examples out!  If you
  378.          type "send cls|command" at the DOS command line, the letters "cls"
  379.          will appear on your screen after the copyright for the appropriate
  380.          version of DOS.  However, when you try to push the <Enter> key
  381.          nothing will happen.  You told the new command.com to take its
  382.          input from the output of SEND and it stubbornly won't take any from
  383.          you; the only keystroke to which it will respond is the one
  384.          requiring three fingers!  So you might try, "send cls$_|command".
  385.          This will work in the sense that your screen will clear but after
  386.          that, the system will hang.  The correct thing to do is "send
  387.          cls$_exit$_|command".  This will clear the screen and unload the
  388.          new shell of command.com returning control to you.  So the moral is
  389.          whenever piping send's output through COMMAND.COM you should be
  390.          sure that the end of the string in "send 'string'|command" is
  391.                "$_exit$_"
  392.                Of course, you'd never use this redirection to clear the
  393.          screen.  Here are two possible uses.  You might make a batch file
  394.          called return.bat with the single line:
  395.                send %1 %2$_$n:$_cd $p$_exit$_|command
  396.          Thus, if you have a batch file lotus.bat which switches to the
  397.          directory with 123 and runs it, typing "return lotus" will run
  398.          lotus.bat and then return you to the drive and directory that you
  399.          started on.  You needn't worry that having told COMMAND.COM to only
  400.          accept input from the output of SEND, your keyboard will be locked
  401.          up when you try to communicate with 123.  COMMAND.COM will not
  402.          accept input from the keyboard, but it has loaded 123 which is
  403.          configured to take input from the keyboard.  However, if you run a
  404.          program with return.bat that tries to issue commands to DOS, it may
  405.          not work.  Mind you, there will be no problem with the program
  406.          using DOS services as it might in saving a file.
  407.                Here is another use.  Suppose that your communication program
  408.          captures input into a file named "temp" by default.  You want to
  409.          make a batch file which collects your electronic mail and stores it
  410.          in a file whose name is stamped with today's date.  Include the
  411.          line
  412.                send ren temp mail$M$D.$Y $_exit$_|command
  413.          in the file and things will work exactly as you wish.
  414.  
  415.  
  416.                                       SEND  page 6
  417.  
  418.                In this last example, it is important to mention that when
  419.          you exit an extra shell of DOS, it returns control to the calling
  420.          program, even if the calling program is a batch file.  Thus the
  421.          above line will work fine even in the middle of a batch file.
  422.                Two warnigs: NEVER load a program that becomes permanently
  423.          resident in the string you send to COMMAND.COM.  You will then be
  424.          unable to exit the new DOS shell and your system will hang.  Do not
  425.          try to change environmental variables (path, prompt, etc.) with the
  426.          command string.  Nothing bad will happen but the change will only
  427.          take effect in the new shell and when it is exited, the changes
  428.          will be lost.
  429.  
  430.          SUMMARY
  431.                SEND works just like the ECHO command in DOS (including the
  432.          fact that its output but not its input can be redirected) except:
  433.                1. CR-LF pairs are not automatically inserted at the end of
  434.          each line but must be inserted (either as $_ or as ^M^J) at any
  435.          desired point.
  436.                2. ^ and $ are not interpreted in the usual way but have
  437.          special meanings; "$$" will be interpreted as "$" and "$^" as "^".
  438.                3. ^ followed by any letter (upper or lower case) or the
  439.          other appropriate symbols (@,[,\,^,_) are interpreted as the
  440.          corresponding control characters.  In particular, ^[ will send an
  441.          <Esc> (ASCII 27). It is better not to follow ^ by any other symbol.
  442.                4. $ followed by ^,P,M,D,Y,T or any of the PROMPT meta
  443.          characters ($,t,d,p,v,n,g,l,b,q,h,e,_) has the meaning given in the
  444.          DOS manual description of the PROMPT.  $^ gives a literal ^ and $P
  445.          means the same a $p in the root directory and the same as $p\ in
  446.          any other directory.  $h does not have the PROMPT meaning of
  447.          backspace AND ERASE but only means backspace, i.e. <Ctrl H> (ASCII
  448.          8).  In particular, $e  will send an <Esc> (ASCII 27) and $_ a CR-
  449.          LF pair.  $M,$D,$Y return two digits for the month, day and year.
  450.          $T returns the four digits HHMM in the time.
  451.  
  452.  
  453.          HISTORY
  454.  
  455.          Version 1.0                               10-15-85
  456.  
  457.          Version 1.5                               12-05-85
  458.                Added $M,D,Y,T commands and added to the documentation the
  459.          possibility of piping send throungh COMMAND.COM
  460.  
  461.          Version 1.6                               01-03-86
  462.                Modified send to work properly with XCED, a part of the PCED
  463.          package.  Previously, send assumed it command input ended with a CR
  464.          which DOS automatically inserts at the end of command lines.  Now
  465.          send ends its input when it reaches a NULL (ASCII 0) or the number
  466.          of characters specified by DOS for the input, whichever comes
  467.          first.
  468.          ¢0 L
  469.